﻿using AntMovement.Core.Entity;
using AntMovement.Core.Hardware;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AntMovement.SDK.LTSMC.Logic
{
    public class AxitHardware : IAxis
    {
        private Axis _axit;
        public AxitHardware(Axis axis)
        {
            _axit = axis;
        }

        public string ClearCEnc()
        {
            throw new NotImplementedException();
        }

        public string ClearCPos()
        {
            throw new NotImplementedException();
        }

        public string ContinuousMotion(bool bl)
        {
            short error = LTSMC.smc_vmove(_axit.CardNo, _axit.AxisID, (ushort)(bl ? 1 : 0));
            if (error != 0)
            {
                throw new Exception($"CardNo[{_axit.CardNo}] Index[{_axit.AxisID}] smc_vmove[{error}]");
            }
            return "ok";
        }

        public AxisParameter GetAxisParameter() => _axit.Parameter;
        public AxisStatus GetAxisStatus() => _axit.Status;

        public string HomeMove()
        {
            return "ok";
        }

        public string Move(long dist, int dist_mode, int vel_mode)
        {
            return "ok";
        }

        public string SetProfile()
        {
            return "ok";
        }

        public string SetServo(bool enable)
        {
            throw new NotImplementedException();
        }

        public string Stop(int emgStop)
        {
            short error = LTSMC.smc_stop(_axit.CardNo, _axit.AxisID, (ushort)emgStop);
            if (error == 0)
            {
                throw new Exception($"CardNo[{_axit.CardNo}] Index[{_axit.AxisID}] smc_vmove[{error}]");
            }
            return "ok";
        }
    }
}
